The Thomson MO6 computer contains two Basic in the ROM, the Basic 128 Microsoft 1.0 and the Basic Microsoft 1.0, the latter allows compatibility with the previous model Thomson MO5

*** The BASIC used for this program is Microsoft's Basic 128 1.0 which takes advantage of the new features of the MO6 ***

Description of the line by line code:

Line 0:
The CLEAR statement is used to reserve space for 5 redefined characters in memory; character (2 chars), flames (2 chars), cake base decoration (1 char)
DEFINT defines all variables as an integer type.
SCREEN sets the colors of the screen and the next FOR loop sets the colors of the palette via READ from the list of DATA values ​​in line 3
The line ends with a series of LINE, BOXF and PSET instructions which are used to draw 2 blocks to build the cake platforms.

Line 1:
More instructions to finish drawing the tile graphics.
Matrix B (40) is defined which stores the images of the 2 tiles via GET
Some variables used in the game and other numerals used by the following FOR ... NEXT cycle are defined to draw the background gradient via BOXF.

Line 2:
NEXT closes the FOR of the upper line positioned here because line 1 ends with the condition IF ... THEN;
DEFGRS (4) defines the character used to decorate the base of the cake;
ATTRB sets the size of the text to be printed, 0.0 corresponds to the normal size;
CONSOLE ,,, 2 fixes the scrolling of the page, the FOR loop is used to create the base of the pie by means of the LOCATE statement which positions the cursor in the X, Y and PRINTGR$(4) prints the redefined character n.4
CONSOLE 0.23,, 0 defines the display area of ​​the screen in character mode, it is used to prevent the CLS (Clear Screen) instruction used by the program from erasing the base of the cake.
Character n.0 is defined through the DEFGRS (0) instruction and some variables are initialized, partly useful for the graphic construction of the cake platforms and others for the logic of the game.

Line 3
The first FOR ... NEXT loop loads the X, Y position of the flames into the two-dimensional matrix F via the READ from the first DATA of the line 9
The second FOR ... NEXT loop loads the text contained in the second DATA of line 9 into the T$ matrix
Some variables are defined (see list at the end of the page)

Line 4:
Here we are at the construction of the cake which takes place platform by platform through the first FOR cycle which is repeated several times in relation to the result of the condition IF N> 0 NEXT GOTO 4 on the contrary, thanks to ELSE, execution continues on the same line and two FOR cycles are performed with nesting to draw the candles recovering the position from the 2-dimensional matrix F. (The LINE command inside the cycle is used to assign the red color to the area that will contain the flames).
CONSOLE ,, 1 is used to fix the screen colors and prevent elements drawn in the foreground color (character, flowing text and flames) from erasing the background while moving.

Line 5:
(From here begins the logic of the game and the main loop through the GOTO)
The double-sized GR $ (G) character is printed thanks to ATTRB 1.1.
PRINTUSING "&"; T $ (T) printed texts that scroll from top to bottom.
The condition IF M> W + 3 verifies that the flowing text does not exceed the character vertically and if the condition is true it cancels it with PRINTUSING "&";S$
A new random value from one to ten is assigned to the variable T with the T=RND(PEEK(8241))*10+1. 
The condition following ELSE determines whether a collision occurred between the writing and the character by comparing the values ​​of the Y coordinates of both, if the condition is true, the value 1 is assigned to the variable E and passes the execution of the program to line 9

Line 6:
IFK = 15 checks that the number of blown out candles is equal to 15 and if the condition is true then the text of the variable T $ is printed and a FOR loop is executed which reproduces cacophonic music 8 times through the PLAY instruction.
At the end of the for loop, the execution of the program switches to line 0 (the game restarts). If the IF condition is false, execution continues on the same line.
S$=SPACE$(LEN(T$(T))+2) assigns to the string S $ a number of spaces equal to the number of characters of the matrix T $ (T),it is used to erase the trace of the flowing text.
The two FOR loops with nesting are used to draw the flames of the candles GR$ (A),
the value of variable A changes cyclically between 0 and 1 thanks to the assignment A = A XOR1 in line 5, in this way, two different characters redefined for the flames are printed alternately giving the effect of animation to the flames.

Line 7:
The two NEXTs close the FOR loops of the previous line.
The value of the joystick position is assigned to variable J via J = STICK(0) and the respective checks are performed.
If the joystick is in position 5 (low) it means that you are blowing to extinguish a flame.
D=Q+1 assigns to the variable D the position X of the character which is compared with the value of the position of the flames contained in the matrix D. This occurs through the FORZ = 0TO4 cycle within which the condition IFD = F (L, Z) is found, which contains the value of the position of the flames.
If the condition is true: 
LOCATEQ+1,W+1:PRINT"|": clear the flame;
F(L,Z)=0:K=K+1 sets the previous value of the flame position to 0 and increases the value of K by 1 (counting candles off).
The next two IFs take care of moving the character left and right based on the position of the Joystick

Line 8:
The first IF condition deals with the vertical movement of the character (jump)
PX=Q*8:PY=W*8+8: the pixel values ​​of the sprite position are assigned to the variables PX and PY (Q and W contain the coordinates in character mode 24 linne x 48 columns of the sprite, you need to convert them to pixels because they are needed for subsequent POINT instructions)
The POINT (X, Y) function returns the number corresponding to the color of a certain point on the screen.
The IFPOINT (PX, PY) <> - 7ANDPOINT (PX + 16, PY) <> - 7 checks that the background color -7 is present at the base of the sprite, if the condition is false it means that there is no ground underfoot and the character falls.
IFW>=23THENE=1:GOTO9 if the sprite passes it, the limit of the first platform is GAME OVER

Line 9
IFE = 1 checks the state of life (0 = alive / 1 = dead), if the condition is true PRINT O $ print the banner "GAME OVER".
PLAY D$ produces a sound, CONSOLE ,, 0 resets the graphic tracing mode in order to be able to redraw the graphics when execution passes to line 0 through the next GOTO 0. 
The line ends with 2 DATA Instructions, the first contains the values ​​of the position of the flames (groups of 5 values ​​per line), the second the texts of the writings that chase the sprite.


Main game variables used by line 5

A = Candle frame number
Q = Position x of the sprite
W = Position y of the sprite
M = Position y of text flowing from above
T = ID of top-down text randomly generated with RND
D = Position of the sprite over the candle
L = Platform number where the sprite is located
K = Number of candles blown out
J = Joystick position
G = Sprite frame (2=normal / 3=puff)
E = Life status (0 = alive / 1 = dead)
F() = Matrix containing the position of the flames
T$() = Matrix containing the texts that flow from the topo

These indications help you find your way around the code to better understand it and possibly improve it.










